package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysMenu;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysMenuProperties;
import com.ruoyi.system.service.ISysMenuPropertiesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜单属性Controller
 * 
 * @author huikai
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/system/menuProperties")
public class SysMenuPropertiesController extends BaseController
{
    @Autowired
    private ISysMenuPropertiesService sysMenuPropertiesService;

    /**
     * 查询菜单属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMenuProperties sysMenuProperties)
    {
        startPage();
        List<SysMenuProperties> list = sysMenuPropertiesService.selectSysMenuPropertiesList(sysMenuProperties);
        return getDataTable(list);
    }

    /**
     * 导出菜单属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:menu:export')")
    @Log(title = "菜单属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMenuProperties sysMenuProperties)
    {
        List<SysMenuProperties> list = sysMenuPropertiesService.selectSysMenuPropertiesList(sysMenuProperties);
        ExcelUtil<SysMenuProperties> util = new ExcelUtil<SysMenuProperties>(SysMenuProperties.class);
        util.exportExcel(response, list, "菜单属性数据");
    }

    /**
     * 获取菜单属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:menu:query')")
    @GetMapping(value = "/{propertiesId}")
    public AjaxResult getInfo(@PathVariable("propertiesId") Long propertiesId)
    {
        return success(sysMenuPropertiesService.selectSysMenuPropertiesByPropertiesId(propertiesId));
    }

    /**
     * 新增菜单属性
     */
    @PreAuthorize("@ss.hasPermi('system:menu:add')")
    @Log(title = "菜单属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMenuProperties sysMenuProperties)
    {
        sysMenuProperties.setCreateBy(getUsername());
        return toAjax(sysMenuPropertiesService.insertSysMenuProperties(sysMenuProperties));
    }

    /**
     * 修改菜单属性
     */
    @PreAuthorize("@ss.hasPermi('system:menu:edit')")
    @Log(title = "菜单属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMenuProperties sysMenuProperties)
    {
        sysMenuProperties.setUpdateBy(getUsername());
        return toAjax(sysMenuPropertiesService.updateSysMenuProperties(sysMenuProperties));
    }

    /**
     * 删除菜单属性
     */
    @PreAuthorize("@ss.hasPermi('system:menu:remove')")
    @Log(title = "菜单属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{propertiesIds}")
    public AjaxResult remove(@PathVariable Long[] propertiesIds)
    {
        return toAjax(sysMenuPropertiesService.deleteSysMenuPropertiesByPropertiesIds(propertiesIds));
    }
}
